// ... existing imports and initial code ...

# 添加目录生成方式的选择函数
def get_folder_structure_choice():
    while True:
        print("\n请选择文件夹生成方式：")
        print("1. 按时间生成文件夹")
        print("2. 按商家名称生成文件夹")
        choice = input("请输入选择（1 或 2）: ")
        if choice in ['1', '2']:
            return choice
        print("无效的选择，请重新输入")

# 修改 download_image 函数
def download_image(row):
    global completed_tasks

    index, data = row

    # 获取图片 url、订单号和就诊时间
    image_url = data['图片']
    order_number = data['订单单号']
    visit_time = data['就诊时间']
    store_name = data['商家']

    # 如果 url 为空、order_number 为空或 visit_time 为空，order_number 为 \N 则跳过
    if pd.isnull(image_url) or pd.isnull(order_number) or pd.isnull(visit_time) or order_number == '\\N':
        return

    # 根据用户选择决定文件夹名称
    if folder_structure_choice == '1':
        folder_name = parse_date(visit_time)
    else:
        folder_name = store_name if not pd.isnull(store_name) else "未知商家"

    folder_path = os.path.join(current_dir, folder_name)

    # ... rest of the download_image function remains the same ...

# 在开始下载之前获取用户选择
folder_structure_choice = get_folder_structure_choice()

print(f"\n开始下载，共 {total_tasks} 张图片，最大线程数为 {max_workers} 个")

// ... rest of the code remains the same ...